<template>
  <div>
    <nav-bar :title="title" :isShow="false"></nav-bar>
    <van-form>
      <van-field
        v-model="name"
        name="name"
        label="姓名"
        placeholder="姓名"
        :rules="[{ required: true, message: '请填写姓名' }]"
      />
      <van-field
        v-model="code"
        name="code"
        label="咨询卡号"
        placeholder="咨询卡号"
      />
      <van-field
        v-model="card_name"
        name="card_name"
        label="名称"
        placeholder="名称"
      />
      <van-field
        v-model="used"
        name="used"
        label="状态"
        placeholder="状态"
        readonly
      />
      <div style="margin: 16px;">
         <go-home-button></go-home-button>
      </div>
    </van-form>
   
  </div>
</template>

<script>
import NavBar from '@/components/NavBar'
import GoHomeButton from '@/components/GoHomeButton'
import { card_consult_update } from '@/api/service'
import { get_role } from "@/api/role";

export default {
  components: {
    NavBar,
    GoHomeButton
  },
  props: {
    card_id: String
  },
  data() {
    return {
      title: this.$route.meta.title || "",
      is_used: 0,
      code: "",
      card_name: "",
      name: "",
    };
  },
  computed:{
    used(){
      if(this.is_used === 1){
        return '确认成功'
      }else{
        return '未用'
      }
    }
  },
  methods: {
    async ConfirmCardConsult(){
      let openid = localStorage.getItem("openid");
      const { data: res} = await get_role(openid)
      console.log('ddddd:',res);
      if(!res){
        this.$toast('咨询卡确认请求失败!')
        return
      }
      if(res.member_role === 1 || res.member_role === 3){
          console.log(res.member_role);
      }else{
        this.$toast('您无权确认咨询卡')
        this.$router.replace("/")
      }
      const data = {
        id: this.card_id,
        is_used: 1
      }
      card_consult_update(data).then(res=>{
        console.log("ConfirmCardConsult:", res)
        this.code = res.data.code
        this.card_name = res.data.card_name
        this.name = res.data.name
        this.is_used = res.data.is_used
      }).catch(error => {
        if (error.response) {
          console.log(error.response.data);
        } else if (error.request) {
          console.log(error.request);
        } else {
          console.log('Error', error.message);
        }
        console.log(error.config);
      })
    },

  },
  created() {
    console.log(this.card_id);
    this.ConfirmCardConsult()
  },

};
</script>

<style  scoped>

</style>